package com.focus.xyz.union.pages.backend;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.utils.Constants;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import java.util.List;

/**
 * Created by chenmeng on 2016/5/23.
 */
public class MemInfoPage {

    private Action action;

    @FindBy(id = "dev_btn_balance_mode")
    private WebElement modSettleTypeBtn;

    @FindBy(xpath = "//*[@id=\"dev_balanceMode_div\"]/div[1]/table/tbody/tr/td")
    public List<WebElement> settleType;
    @FindBy(id = "dev_baclance_submit")
    public WebElement submitBtn;

    public MemInfoPage(WebDriver driver,Action action){
        this.action = action;
        PageFactory.initElements(driver,this);
    }

    public void modifySettleType(String type) throws Exception{
        action.click(modSettleTypeBtn);
        if(!settleType.isEmpty()){
            for(WebElement cc:settleType){
                WebElement radio = cc.findElement(By.tagName(Constants.TAG_INPUT));
                if(cc.getText().trim().equals(type)){
                    action.click(radio);
                    break;
                }
            }
        }
        action.click(submitBtn);
        action.pause(1000l);
        action.acceptAlert();
    }
}
